Skip to content

Conversation

@eliashaeussler
Copy link

This PR implements a new rule for unserialize. Following behaviors will trigger an error:

  • Parameter $2 options is NOT set (only with parameter checkInsecureUnserialize: true)
  • Parameter $2 options has an invalid array key (neither allowed_classes nor max_depth)
  • Parameter $2 options has invalid type for allowed_classes
  • Parameter $2 options has 'allowed_classes' => true (only with parameter checkInsecureUnserialize: true)
  • Parameter $2 options has invalid array item for allowed_classes
  • Parameter $2 options has max_depth key on PHP < 7.4
  • Parameter $2 options has invalid type for max_depth
  • Parameter $2 options is set, but does not have allowed_classes configured (only with parameter checkInsecureUnserialize: true)

@eliashaeussler eliashaeussler force-pushed the feature/unserialize branch 2 times, most recently from d868abd to 0bf9e38 Compare January 14, 2026 08:46
$this->analyse([__DIR__ . '/data/unserialize.php'], $expectedErrors);
}

#[RequiresPhp('< 7.4')]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether to keep this test case, since it does not seem like PHP < 7.4 is actually included in the test matrix.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. This is a new rule, should only be enabled with bleeding edge using conditionalTags in config.
  2. Some things this rule reports should be achieved by changing resources/functionMap files (the deltas) - this will make existing rule to pick up the errors. I'm thinking about:
  • Parameter #2 $options to function unserialize contains an invalid value null for "max_depth"
  • Parameter #2 $options to function unserialize contains unsupported option "foo".
  • Parameter #2 $options to function unserialize contains an option "max_depth" which is not supported by this PHP version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants